package com.coin900.coin.cmd.capital;

import com.coin900.coin.base.FuConstants;
import com.coin900.coin.cmd.ACmd;
import com.coin900.coin.cmd.CmdSign;
import com.coin900.coin.code.CmdCode;
import com.coin900.coin.code.RespCode;
import com.coin900.coin.persist.fu.FuCapitalWithdrawVO;
import com.coin900.coin.service.fu.IFuCapitalWithdrawService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 资产提现审核列表
 *
 * @author shui
 * @create 2017-12-18
 **/
@Controller
public class FuCapitalWithdrawCheckCmd extends ACmd {
    @Override
    public CmdSign execute(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        String source = sign.getSource();
        JSONObject jsonObject = JSONObject.fromObject(source);
        long id = jsonObject.getLong("id");
        int checkStatus = jsonObject.getInt("checkStatus");

        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        params.put("dataStatus", 1);
        List<FuCapitalWithdrawVO> fuCapitalWithdrawVOS = this.withdrawService.loadFuCapitalWithdraw(params);
        if (fuCapitalWithdrawVOS.isEmpty()) {
            respSign.setRespCode(RespCode.FAIL);
            respSign.setMsg("提现申请不存在");
            return respSign;
        }

        FuCapitalWithdrawVO fuCapitalWithdrawVO = fuCapitalWithdrawVOS.get(0);
        fuCapitalWithdrawVO.setCheckStatus(checkStatus);
        fuCapitalWithdrawVO.setModifiedInfor(super.getUser(sign));
        fuCapitalWithdrawVO.setCheckTime(fuCapitalWithdrawVO.getModifiedDate());

        this.withdrawService.checkFuCapitalWithdraw(fuCapitalWithdrawVO);
        return respSign;
    }

    @Autowired
    private IFuCapitalWithdrawService withdrawService;

    @Override
    public String getCmdCode() {
        return CmdCode.FU_CAPITAL_WITHDRAW_CHECK;
    }
}
